CentOS 5
Sponsored Link

Install PostgreSQL
2015/01/15
  Install PostgreSQL for database server.
[root@www ~]#
yum -y install postgresql-server
[root@www ~]#
vi /var/lib/pgsql/data/postgresql.conf
# line 49: uncomment and change (listen all)

listen_addresses = '
*
'
# line 300: uncomment and change (change log format)

log_line_prefix = '
%t %u %d
'
[root@www ~]#
/etc/rc.d/init.d/postgresql start

Initializing database:
[ OK ]

Starting postgresql service:
[ OK ]

[root@www ~]#
chkconfig postgresql on
[root@www ~]#
su - postgres
# switch to the postgres user

# set password for postgres user

-bash-3.2$
psql -c "alter user postgres with password 'password'"

ALTER ROLE
-bash-3.2$
createuser cent
# create a DB user "cent"

Shall the new role be a superuser? (y/n)
y
# set privilege if you want

CREATE ROLE
-bash-3.2$
su - cent
# switch to the "cent" user on OS

Password:
[cent@www ~]$
createdb testdb
# create a test DB

CREATE DATABASE
[cent@www ~]$
psql -l
# show DB

        List of databases
   Name    |  Owner   | Encoding
-----------+----------+----------
 postgres  | postgres | UTF8
 template0 | postgres | UTF8
 template1 | postgres | UTF8
 testdb    | cent     | UTF8
(4 rows)

[cent@www ~]$
psql testdb
# connect to the test DB

Welcome to psql 8.1.23, the PostgreSQL interactive terminal.

Type:  \copyright for distribution terms
       \h for help with SQL commands
       \? for help with psql commands
       \g or terminate with semicolon to execute query
       \q to quit

# set password

testdb=#
alter user cent with password 'password';

ALTER ROLE
# create a test table

testdb=#
create table test ( no int,name text );

CREATE TABLE
# insert test data

testdb=#
insert into test (no,name) values (1,'cent');

INSERT 0 1
# confirm

testdb=#
select * from test;
 no | name
----+-------
  1 | cent
(1 row)
# remove test table

testdb=#
drop table test;

DROP TABLE
# quit

testdb=#
\q
[cent@www ~]$
dropdb testdb
# remove test DB
 
Tweet